(function () {

	function p(a,b){
		return a.position = b;
	}

	var h = {},
		r = true,
		q = document.getElementById('hplogo');
		x = -999,
		y = -999,
		t = [
			["#994d33", 6],
            ["#994d33", 4],
            ["#733a26", 4]	
		],
		/**
			ix -- the original x coordinates
			iy -- the original y coordinates
			iw -- the original width
			ih -- the original height
			jx -- the last x coordinates
			jy -- the last y coordinates
			jw -- the last width
			jh -- the last height
			jh -- the last height
			id -- id
			pd -- the numb of the photo
			pt -- the offset of the photo
			bg -- background-color
		*/
		generate = function(ix,iy,iw,ih,jx,jy,jw,jh,id,pd,pt,bg){
			this.ix = this.sx = ix;
			this.iy = this.sy = iy;
			this.jx = jx;
			this.jy = jy;
			this.iw = this.sw = iw;
			this.ih = this.sh = ih;
			
			this.ox = jx - ix;
			this.oy = jy - iy;
			
			this.bg = t[bg][0];
			this.edge = t[bg][1];

			this.ow = jw - iw + 2*this.edge;
			this.oh = jh - ih + 2*this.edge;
		
			this.pt = pt;
			this.scale = this.n = 0;
			
			
			
			c = document.createElement('div');
			a = this.bgdiv = c.style;
			a.backgroundColor = this.bg;
			c.id = 'hplogo-' + id;
			
			(b = document.getElementById(c.id)) 
				&& b.parentNode 
				&& b.parentNode.removeChild(b);
			
			q.appendChild(c);


			e = document.createElement('div');
			b = this.wrap = e.style;
			b.overflow = 'hidden';
			b.top = this.edge + 'px';
			b.left = this.edge + 'px';
			c.appendChild(e);

			c = document.createElement('a');
			c.href = '#';
			e.appendChild(c);

			f = document.createElement('img');
			e = this.img = f.style;
			f.src = "../html/images/google/holiday10-hp-" + pd + ".jpg";
			f.border = 0;
			c.appendChild(f);

			p(a, p(b, p(e,'absolute')));
			this.position(17, true);
		};
	
	
	p(generate.prototype, function(a, b){
		var bgdiv = this.bgdiv,
			scale = this.n - this.scale;

		if(b || Math.abs(scale) > 0.01){
			var g = 0.55;
			if(scale < 0) g /= 2;

			this.scale += g*scale;
			g = Math.ceil(this.sx + this.scale * this.ox);
			var m = Math.ceil(this.sy + this.scale*this.oy),
				o = Math.floor(this.sw + this.scale*this.ow),
				p = Math.floor(this.sh + this.scale*this.oh),
				f = g + o < this.ix + this.iw;
			
			if(scale > 0 && f || scale < 0 && !f) 
				o = this.ix + this.iw - g;
			
			f = m + p < this.iy + this.ih;
			
			if(scale > 0 && f || scale < 0 && !f) 
				p = this.iy + this.ih - m;
			
			
			this.ix = g;
            this.iy = m;
            this.iw = o;
            this.ih = p;
            bgdiv.width = this.iw + "px";
            bgdiv.height = this.ih + "px";
            bgdiv.left = this.ix + "px";
            bgdiv.top = this.iy + "px";
			this.wrap.height = this.ih - this.edge * 2 + "px";
			this.wrap.width = this.iw - this.edge * 2 + "px";
            this.img.left = this.jx - this.ix + "px";
            this.img.top = this.jy - this.iy - this.pt + "px"
		}

		bgdiv.zIndex = 17 - a;
	});

	generate.prototype.update = function(){
		this.n = x > this.sx && 
            	 y > this.sy && 
            	 x < this.sx + this.sw && 
            	 y < this.sy + this.sh ? 1 : x > this.sx - 20 && 
            	 y > this.sy - 20 && 
            	 x < this.sx + 20 + this.sw && 
            	 y < this.sy + 20 + this.sh ? 1 / 6 : 0
	};
	
	var 
		imgarry = 
			[new generate(255, 28, 61, 50, 217, 28, 158, 123, 1, 6, 0, 2), 
        	 new generate(277, 82, 73, 49, 191, 45, 209, 131, 2, 6, 271, 0), 
        	 new generate(207, 97, 58, 66, 167, 81, 211, 100, 3, 4, 238, 1), 
        	 new generate(337, 137, 74, 50, 337, 63, 214, 116, 4, 2, 163, 1), 
        	 new generate(162, 40, 81, 50, 160, 13, 91, 120, 5, 4, 118, 1), 
        	 new generate(165, 6, 67, 29, 36, 6, 188, 118, 6, 4, 0, 2), 
        	 new generate(322, 15, 35, 50, 255, 4, 130, 148, 7, 6, 123, 0), 
        	 new generate(506, 39, 97, 72, 296, 16, 314, 135, 8, 5, 0, 0), 
        	 new generate(73, 22, 73, 56, 54, 22, 172, 109, 9, 1, 0, 0), 
        	 new generate(367, 41, 59, 90, 292, -3, 126, 163, 10, 2, 0, 2), 
        	 new generate(78, 85, 54, 94, -35, 1, 175, 179, 11, 1, 220, 2), 
        	 new generate(-7, 37, 72, 111, -29, 30, 190, 110, 12, 1, 109, 0), 
        	 new generate(152, 95, 44, 55, 100, 11, 143, 165, 13, 4, 338, 0), 
        	 new generate(283, 136, 33, 34, 229, 93, 115, 78, 14, 6, 402, 2), 
        	 new generate(439, 13, 51, 125, 400, 2, 133, 128, 15, 3, 0, 1), 
        	 new generate(501, 117, 64, 50, 402, 46, 204, 131, 16, 5, 135, 2), 
        	 new generate(429, 141, 49, 43, 429, 45, 148, 131, 17, 3, 128, 0)],	
	
		detectmc = function(e){
			e = e || window.event;
			//x = e.clientX - q.offsetLeft + (document.body.scrollLeft || document.documentElement.scrollLeft);
			//y = e.clientY - q.offsetTop + (document.body.scrollTop || document.documentElement.scrollTop);
			x = e.clientX - $$OBEA.rect(q).left + (document.body.scrollLeft || document.documentElement.scrollLeft);
			y = e.clientY - $$OBEA.rect(q).top + (document.body.scrollTop || document.documentElement.scrollTop);
		};

	if(!h.sleek) h.sleek = {};
	
	h.sleek.hover = function(e){
		if(r){
			r = false;
			window.setTimeout(function(){
				r = true;
			},50);
			detectmc(e);
		}
	};

	h.sleek.hide = function(e){
		detectmc(e);
		if(x <= 0 || x >= q.offsetWidth || y <= 0 || y >= q.offsetHeight - 10)
			x = y = -999;
	};
	
	if(h.sleek.k){
		window.clearInterval(h.sleek.k);
		h.sleek.k = null;
	}
	h.sleek.k = window.setInterval(function(){
		for (var a = 0, b; b = imgarry[a++];) b.update();
            imgarry.sort(function (c, e) {
                var g = e['scale'] - c['scale'];
                return g < 0 ? -1 : g == 0 ? 0 : 1;
            });
        for (a = 0; b = imgarry[a];) b.position(a++);
	},50);
	window.h = h;
	
})();